
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>我的订单</title>
    {include file="public/head" /}
<body>
<div class="headtop mfc fl">
    <div class="mfc fl myorder-menu bsilk wenSwim bc-white">
        <ul>
            <li class="active" onclick="search(0,this)">全部</li>
            <li onclick="search(1,this)">已下单</li>
            <li onclick="search(23,this)">待收货</li>
            <li onclick="search(4,this)">已完成</li>
            <li onclick="search(5,this)">退款/退单</li>
        </ul>
    </div>
</div>
<div class="mfc myorder-list fl" id="data">

</div>
</body>
</html>
<script>
    var data;
    localStorage.setItem('page', 1);
    localStorage.setItem('status', 0);
    function search(status=0,t) {
        $(t).addClass('active').siblings().removeClass('active');
        localStorage.setItem('status', status);

        data();
    }
    $(function(){

        $(window).scroll(function () {
            localStorage.setItem('type', 2);
            var page = parseInt(localStorage.getItem('page'));
            var scrollTop = $(this).scrollTop();               //滚动条距离顶部的高度
            var scrollHeight = $(document).height();           //当前页面的总高度
            var windowHeight = $(this).height();               //当前可视的页面高度
            if (scrollTop + windowHeight >= scrollHeight) { //距离顶部+当前高度 >=文档总高度 即代表滑动到底部
                page += 1;
                localStorage.setItem('page', page);
                data();
            }
        })
        data = function data() {
            var page = localStorage.getItem('page');
            var status = localStorage.getItem('status');
            var type = localStorage.getItem('type');

            $.ajax({
                type: "POST", //用POST方式传输
                dataType: "json", //数据格式:JSON
                data:{page:page,status:status},
                url: "{:url('Order/ajax')}", //目标地址
                async: false,
                success: function (ret) {

                    //console.log(ret.data.data);
                    if(ret.data.data.length === 0 && type == 1){
                        layer.msg('搜索结果为空');
                    }
                    if(ret.data.data.length === 0 && type == 2){
                        layer.msg('没有数据了');
                    }
                    if(ret.code == 200){

                        var str = '';
                        $.each(ret.data.data, function(k, v) {

                            str += '<div class="cell">\n' +
                                '\t\t\t<div class="card myorder-list-place">\n' +
                                '\t\t\t\t<div class="head">\n' +
                                '\t\t\t\t\t<p class="bsilk">\n' +
                                '\t\t\t\t\t\t<span>'+v.create_time+'</span>\n' +
                                '\t\t\t\t\t\t<span class="c-red fr">'+v.status_text+'</span>\n' +
                                '\t\t\t\t\t</p>\n' +
                                '\t\t\t\t</div>\n' +
                                $.each(ret.data.data,function (k2,v2) {
                                    console.log(v.OrderGoods);
                                    str += 123;

                                })
                                '\t\t\t\t<div class="idenr">\n' +
                                '\t\t\t\t\t<p class="lh30">\n' +
                                '\t\t\t\t\t\t<span class="fs08">订单编号：</span>\n' +
                                '\t\t\t\t\t\t<span class="imark">'+strLength(v.order_number,4)+'</span>\n' +
                                '\t\t\t\t\t\t<button class="btnbox fr enter">确认收货</button>\n' +
                                '\t\t\t\t\t\t<button class="btnbox fr">申请退款</button>\n' +
                                '\t\t\t\t\t</p>\n' +
                                '\t\t\t\t</div>\n' +
                                '\t\t\t</div>\n' +
                                '\t\t</div>';


                        });
                        if(page == 1){ //
                            $("#data").html('');
                        }
                        $("#data").append(str);

                    }
                }
            });
        }
        data();

    })


</script>